﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace RAMain.ChartFilterControl
{
    public partial class ChartFilterControl : DevExpress.XtraEditors.XtraUserControl
    {
        public enum SummaryOption
        {
            bytheDay,
            bytheHour
        }

        public DateTime StartTime { get { return fromDateEdit.EditValue != null ? (DateTime)fromDateEdit.EditValue : new DateTime(0); } set { fromDateEdit.EditValue = value;} }
        public DateTime FinishTime { get { return toDateEdit.EditValue != null ? (DateTime)toDateEdit.EditValue : new DateTime(0); } set { toDateEdit.EditValue = value; } }
        public SummaryOption SummaryType { get { return GroupOptions.EditValue !=null ? (SummaryOption)GroupOptions.EditValue: SummaryOption.bytheDay; } set { GroupOptions.EditValue = value;} }
        public bool EnableGroupOptions { get { return GroupOptions.Enabled; } set { GroupOptions.Enabled = value; } }

        public event EventHandler FilterChanged;

        public ChartFilterControl()
        {
            InitializeComponent();            
        }

        private void ChartFilterControl_Load(object sender, EventArgs e)
        {
            GroupOptions.Properties.Items.Add(new DevExpress.XtraEditors.Controls.RadioGroupItem(SummaryOption.bytheDay, "By the day"));
            GroupOptions.Properties.Items.Add(new DevExpress.XtraEditors.Controls.RadioGroupItem(SummaryOption.bytheHour, "By the hour"));
            GroupOptions.EditValue = SummaryOption.bytheDay;
            fromDateEdit.EditValue = null;//DateTime.Now.Date.AddDays(-7);
            toDateEdit.EditValue = null;//DateTime.Now.Date;
        }

        private void GroupOptions_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void fromDateEdit_EditValueChanged(object sender, EventArgs e)
        {
            if (FilterChanged != null && fromDateEdit.EditValue!=null && toDateEdit.EditValue!=null)
            {
                FilterChanged.Invoke(this, e);
            }
        }
    }
}
